<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>讨论(<?php echo $result['count']?>)</title>
        <meta name="viewport" content="initial-scale=1, maximum-scale=1">
        <!--<link rel="shortcut icon" href="/favicon.ico">-->
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <meta name="format-detection" content="address=no">
        <meta name="format-detection" content="email=no">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="stylesheet" href="<?php echo C('STATIC_SHORT_URL');?>/mobile/css/common.css?v=1.0">
        <link rel="stylesheet" href="<?php echo C('STATIC_SHORT_URL');?>/mobile/css/pinglun.css?v=3.7.5">
        <script type="text/javascript" src="<?php echo C('STATIC_SHORT_URL');?>/mobile/js/jquery-1.7.1.js"></script>
        <style>
            header{height:0.8rem;text-align:center;line-height:0.8rem;position:relative;font-size: 0.3rem; color:black;}
            header .onBack{width:0.4rem;height:0.4rem;border:2px solid black ;border-top:none;border-right:none;position:absolute;top:70%;left:5%;margin-top:-0.4rem;-webkit-transform:rotate(45deg);transform:rotate(45deg);}
            header a{text-decoration:none;color:black; height: 0.8rem;display: block ;width: 100%;text-align: center; }
            .number{
                height: 0.8rem;
                color:#797979;
            }
            .tl{
                height: 0.8rem;
            }
        </style>
    </head>
    <body>
<!--    <header>
        <a class="onBack" href="javascript:history.back();"></a>
        <a href="javascript:;" class="tl">讨论 <span class="number">(<?php echo $result['count']?>)</span></a>
    </header>-->
<section>
        <?php if(!empty($result['list'])){ ?>

             <?php foreach($result['list'] as $k =>$v){?>
             <?php if($v['reply_id'] >0){?>
             <div class="part_two part_one" reply_id="<?php echo $v['uid'];?>">
                    <div class="left"> <img src="<?php echo $v['header_img']; ?>"></div>
                    <div id="right"  >
                        <b><?php echo $v['user_name']; ?></b>
                        <?php if($v['level']){?>
                         <h5 id="name" style="color:white;margin: 0;font-size: 0.2rem" ><?php echo $v['level'];?></h5>
                        <?php }?>
                      <span><?php echo $v['announce_time'];?></span>
                      <p  style="margin-top: 0.17rem;margin-bottom: 0.25rem">回复<a href="javascript:;" style="color:#ffbb79;font-size: 0.3rem;" ><?php echo $v['reply_user_name']?></a><?php echo $v['content']?></p>
                  </div>
              </div>
           <?php }else{?>
              <div class="part_one" reply_id="<?php echo $v['uid'];?>">
                 <div class="left" style="border-radius: 50%;" > <img src="<?php echo $v['header_img']; ?>"  ></div>
                 <div class="right"  >
                     <b><?php echo $v['user_name']; ?></b>
                     <?php if($v['level']){?>
                      <h5 id="name1" style="color:white;margin: 0;font-size: 0.2rem" ><?php echo $v['level'];?></h5>
                     <?php }?>
                     <span id="timer" ><?php echo $v['announce_time'];?></span>
                     <p style="margin-top: 0.8rem;font-size: 0.3rem" ><?php echo $v['content']?></p>
                 </div>
             </div>
           <?php } ?>
      <?php }?>


      <?php }else {?>
        <div class="empty" >
              <img src="<?php echo C('STATIC_SHORT_URL') . '/mobile/images/topic/empty1.png'?>" alt="" style="width: 3.58rem;height:1.7rem;" >
              <span style="display: block ;width:100%;color:#dcdcdc;height:0.3rem;font-size: 0.3rem;text-align: center " >暂时没有评论哦~</span>
          </div>

      <?php }?>
</section>
     <footer>
         <span class="bo_picture"></span>
         <input type="text "autocomplete="off" autocorrect="off" placeholder="输入发表你的观点吧！..." >

         <a href="javascript:;" class="sent">发表</a>
     </footer>
      <script>

          //rem自适应代码
          (function(doc, win) {
              var docEl = doc.documentElement,
                      resizeEvt = 'onorientationchange' in window ? 'onorientationchange' : 'resize',
                      recalc = function() {
                          var clientWidth = docEl.clientWidth;
                          if (!clientWidth)
                              return;
                          if (clientWidth >= 750) {
                              docEl.style.fontSize = '100px';
                          } else {
                              docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
                          }
                      };

              if (!doc.addEventListener)
                  return;
              win.addEventListener(resizeEvt, recalc, false);
              doc.addEventListener('DOMContentLoaded', recalc, false);
          })(document, window);
      </script>
<script>
  $(function() {

     var id = <?php  echo $_GET['id'] ?>;

     var reply_uid ='';

     $(document).on("click",".part_one .left",replyName1);
     $(document).on("click",".part_one #right b",replyName1);
          $(document).on("click",".part_one .right b",replyName1);
     $(document).on("click",".part_one",replyName2);

     $(document).on("click",".part_two .left",replyName1);
     $(document).on("click",".part_two #right b",replyName1);
      $(document).on("click",".part_two .right b",replyName1);
     $(document).on("click",".part_two",replyName2);

      function replyName1(event){
//      alert(1);
          var text_name=$(this).parents(".part_one").find("b").html();
          reply_uid = $(this).parents(".part_one").attr("reply_id")
          $('footer input').attr('placeholder','回复：'+text_name);
          event.stopPropagation();//阻止冒泡
      }



      function replyName2(){
          reply_uid = "";
          $('footer input').attr('placeholder',"输入发表你的观点吧！...");
      }

      // 点击发送
      $(".sent").on('click', _click = function() {

          var flag = 0;
          var feedContent = $("footer input").val();
          postAjax(flag,feedContent);
      });
      //请求Ajax
      function postAjax(flag,feedContent){
          var url = 'http://h5.518yin.com/h5/Topic/add_comment';
          $.ajax({
              type: 'get',
              url: url + '?id='+id+"&reply_uid="+reply_uid+"&content="+feedContent,
              dataType: 'json',
              beforeSend: function() {
                  // 禁用按钮防止重复提交
                  $(document).off('click', _click);
              },
              success: function(data) {
                  //数据传递验证成功后执行的操作
                  console.log(data)
                  if (data.code == 200) {
                        window.location.reload();
                  }
              },
              error:function(data){
              console.log(data)
              },
              complete: function() {
                  if (flag == 1) {
                      $(document).off('click', _click);
                  } else {
                      $(document).on('click', _click);
                  }
              },
          });
       }




      var page = 1;
      var ready = true;
      $(document).on('scroll', _scroll = function() {

          var flag = 0; //是否加载到最后一页
          //滚动触发ajax条件
          if (checkscrollside()) {

            page++;
          //  alert(page)
            scrollAjax(page,flag);

          };
      });

      //滚动条件
      function checkscrollside() {
        return ($(document).scrollTop() == $(document).height() - $(window).height()) ? true : false;
      }

      //滚动请求Ajax
      function scrollAjax(page,flag){
              var url1 ='http://h5.518yin.com/h5/Topic/comment';
              $.ajax({
                  type: 'get',
                  url:  url1 + '?page=' + page+"&id="+id,
                  dataType: 'json',
                  timeout: 6000,
                  beforeSend: function() {
                      // 禁用按钮防止重复提交
                      $(document).off('scroll', _scroll);
                  },
                  success: function(data) {
                      console.log(data);
                      //数据传递验证成功后执行的操作
                     if (data.code == 200) {
                        for(var i = 0; i < data.result.list.length; i++) {
                              //alert(data.result[i].reply_id);
                              if( data.result.list[i].reply_id ==null || data.result.list[i].reply_id ==''){
                                   var str1 ='';
                                  if(data.result.list[i].level){
                                      str1 = "<div class='part_one' reply_id="+data.result.list[i].uid+"><div class='left' style='border-radius: 50%;' > <img src="+data.result.list[i].header_img+"></div><div class='right'  ><b>"+data.result.list[i].user_name+"</b><h5 id='name1' style='color:white;margin: 0;font-size: 0.2rem' >"+data.result.list[i].level+"</h5><span id='timer' >"+data.result.list[i].announce_time+"</span><p style='margin-top: 0.8rem;font-size: 0.3rem' >"+data.result.list[i].content+"</p></div></div>";
                                  }else{
                                       str1 = "<div class='part_one' reply_id="+data.result.list[i].uid+"><div class='left' style='border-radius: 50%;' > <img src="+data.result.list[i].header_img+" ></div><div class='right'  ><b>"+data.result.list[i].user_name+"</b><span id='timer' >"+data.result.list[i].announce_time+"</span><p style='margin-top: 0.8rem;font-size: 0.3rem' >"+data.result.list[i].content+"</p></div></div>";
                                  }
                                  $("section").append(str1);

                              }else{
                                  var str2 ='';
                                  if(data.result.list[i].level){
                                       str2 = "<div class='part_one part_two' reply_id="+data.result.list[i].uid+"><div class='left'> <img src="+data.result.list[i].header_img+"  ></div> <div id='right'><b>"+data.result.list[i].user_name+"</b><h5 id='name' style='color:white;margin: 0;font-size: 0.2rem' >"+data.result.list[i].level+"</h5><span>"+data.result.list[i].announce_time+"</span><p  style='margin-top: 0.17rem;margin-bottom: 0.25rem'>回复<a href='javascript:;' style='color:#ffbb79;font-size: 0.3rem;' >"+data.result.list[i].reply_user_name+"</a>"+data.result.list[i].content+"</p></div></div>";
                                  }else{
                                       str2 = "<div class='part_one part_two' reply_id="+data.result.list[i].uid+"><div class='left'> <img src="+data.result.list[i].header_img+"  ></div> <div id='right'><b>"+data.result.list[i].user_name+"</b><span>"+data.result.list[i].announce_time+"</span><p  style='margin-top: 0.17rem;margin-bottom: 0.25rem'>回复<a href='javascript:;' style='color:#ffbb79;font-size: 0.3rem;' >"+data.result.list[i].reply_user_name+"</a>"+data.result.list[i].content+"</p></div></div>";
                                  }
                                  $("section").append(str2);
                              }
                          }
                          if(data.result.list == ""){
                                   flag = 1
                                    $('body').append('<div class="noData" style="font-size:0.25rem">没有更多数据了</div>');

                           }
                      }
                  },
                  complete: function() {
//                        /*没有数据,解除滚动事件*!/
                      if (flag == 1) {
                          $(document).off('scroll', _scroll);
                      } else {
                          $(document).on('scroll', _scroll);
                      }
                  },
              })
      }
});


</script>
</body>
</html>
